//
//  LBNavigationController.m
//  V-Learn
//
//  Created by Apple on 2018/12/20.
//  Copyright © 2018 yxk. All rights reserved.
//

#import "LBNavigationController.h"
#import "UILabel+BRFont.h"
@interface LBNavigationController ()

@end

@implementation LBNavigationController

- (void)viewDidLoad{
    [super viewDidLoad];
    
//    self.navigationBar.translucent = NO;
//    self.navigationBar.barTintColor = [UIColor orangeColor];//BRNavColor;
//    self.navigationBar.tintColor = [UIColor whiteColor];
    UIColor * color = [UIColor whiteColor];
    NSDictionary * dict=[NSDictionary dictionaryWithObject:color forKey:UITextAttributeTextColor];
    
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationBar.backgroundColor = [UIColor whiteColor];

    self.navigationBar.titleTextAttributes = dict;
    
//    [self.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
//
//    self.navigationBar.shadowImage = [[UIImage alloc] init];
    
//    UILabel * tempLabel = [UILabel new];
//    tempLabel.isAdaptiveFont = @"";
//    tempLabel.font = LBFont(17);
////    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
//
//    [self.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:tempLabel.font.pointSize],NSForegroundColorAttributeName:[UIColor blackColor]}];
    
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if (self.viewControllers.count > 0) {
        self.interactivePopGestureRecognizer.enabled = YES;
        if (viewController == self.viewControllers[0]) {
            self.interactivePopGestureRecognizer.delegate = nil; // 不支持侧滑
        } else {
            self.interactivePopGestureRecognizer.delegate = nil; // 支持侧滑
        }
        
        //第二级则隐藏底部Tab
        viewController.hidesBottomBarWhenPushed = YES;
        [self setBack:viewController];
    }
    [super pushViewController:viewController animated:animated];
}
- (void)setBack:(UIViewController *)vc{
    UIButton * btn = [UIButton buttonWithType:(UIButtonTypeCustom)];
//    btn.backgroundColor = [UIColor redColor];
    if (IS_IPHONE_Xs_Max) {
        btn.frame = CGRectMake(0, 0, 32*ScaleX, 32*ScaleX);
    }else{
        btn.frame = CGRectMake(0, 0, 25*ScaleX, 25*ScaleX);
    }
    [btn addTarget:vc action:@selector(BackAction) forControlEvents:(UIControlEventTouchUpInside)];
    UIView * view = [[UIView alloc] initWithFrame: btn.bounds];
    [view addSubview:btn];
    [btn setImage:[UIImage imageNamed:@"back"] forState:(UIControlStateNormal)];
    [btn setImage:[UIImage imageNamed:@"back"] forState:(UIControlStateHighlighted)];
    vc.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:view];
    btn.imageView.contentMode = UIViewContentModeScaleAspectFill;
}

- (void)BackAction{
    [self.navigationController popViewControllerAnimated:YES];
}

- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}

-(nullable UIViewController *)childViewControllerForStatusBarStyle {
    return self.topViewController;
}
@end
